<!--
 * @Author: your name
 * @Date: 2021-06-28 08:50:11
 * @LastEditTime: 2021-06-28 10:49:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue-app\src\views\Home.vue
-->
<template>
  <div>
    <el-table :data="getlist" border style="width: 100%">
      <el-table-column fixed prop="id" label="序号" width="155">
      </el-table-column>
      <el-table-column prop="book" label="书名" width="155"> </el-table-column>
      <el-table-column prop="name" label="作者" width="155"> </el-table-column>
      <el-table-column prop="title" label="类型" width="155"> </el-table-column>
      <el-table-column prop="content" label="数量" width="155">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="155">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row.id)" type="text" size="small"
            >删除</el-button
          >
          <el-button
            @click="handleClicks(scope.row.id)"
            type="text"
            size="small"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <div>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose"
      >
        <div>
          <el-input placeholder="书名" v-model="input" clearable></el-input>
          <el-input placeholder="作者" v-model="input1" clearable></el-input>
          <el-input placeholder="类型" v-model="input2" clearable></el-input>
          <el-input placeholder="库存" v-model="input3" clearable></el-input>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="no">取 消</el-button>
          <el-button type="primary" @click="ok()">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { mapActions, mapMutations, mapState } from "vuex";
export default {
  data() {
    return {
      dialogVisible: false,
      input: "",
      input1: "",
      input2: "",
      input3: "",
      id:""
    };
  },
  created() {
    this.get_list();
  },
  computed: {
    ...mapState(["getlist"]),
  },
  methods: {
    ...mapActions(["get_list"]),
    ...mapMutations(["GET_DEL", "GET_ADD"]),
    handleClick(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          console.log(row);
          this.GET_DEL(row);
          this.get_list();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    handleClicks(row) {
      this.dialogVisible = true
      this.id = row;
    },
    ok() {
      console.log(this.id);
      this.dialogVisible = false;
      this.GET_ADD(this.id);
      this.get_list()
    },
    no() {
      this.dialogVisible = false;
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
  },
};
</script>